<?php
    class StudentDormitoryChangeBLL{
        //获取空宿舍列表
        public function getEmptyDormitoryList($instructorID,$apartment,$search,$page,$pageSize){
            $StudentDormitoryChangeDAL=new StudentDormitoryChangeDAL();
            $result=$StudentDormitoryChangeDAL->getEmptyDormitoryList($instructorID,$apartment,$search,$page*$pageSize,$pageSize);
            $result['page']=$this->getStudentListPage($result['count'],$pageSize);
            $temp=array();
            foreach($result['dormitoryList'] as $dormitory){
                $dormitory['property_name']=$dormitory['property']==1?'女生宿舍':'男生宿舍';
                $temp[]=$dormitory;
            }
            $result['dormitoryList']=$temp;
            return $result;
        }

        //获取学生列表页数
        public function getStudentListPage($count,$pageSize){
            $pageMax=0;
            if($count>$pageSize){
                if($count%$pageSize===0){
                    $pageMax=(int)($count/$pageSize);
                }else{
                    $pageMax=(int)($count/$pageSize)+1;
                }
            }
            
            return $pageMax;
        }

        //将学生调换到空宿舍
        public function exchangeStudentDormitory($exchangeInfo){
            $StudentDormitoryChangeDAL=new StudentDormitoryChangeDAL();
            $result=$StudentDormitoryChangeDAL->exchangeStudentDormitory($exchangeInfo->student_id,$exchangeInfo->apartment_id,$exchangeInfo->floor,$exchangeInfo->dormitory_id);
            if($result){
                $message=array(
                    'code'=>'2001',
                    'message'=>'调换成功'
                );
            }else{
                $message=array(
                    'code'=>'2001',
                    'message'=>'调换失败'
                );
            }

            return $message;
        }
    }
?>